#include "list/circular_list.h"

#include <cassert>
#include <iostream>

ListNode* getCircularListFirstHead(const ListNode* head)
{
    if (nullptr == head || nullptr == head->next)
        return nullptr;

    ListNode *p, *q;
    p = q = head->next;
    while (q != nullptr && q->next != p)
    {
        q = q->next;
    }

    // 不符合定义
    if (nullptr == q->next)
        return nullptr;

    // p == q;
    return p;
}